package top.maof.book.search;

import lombok.AllArgsConstructor;
import lombok.NoArgsConstructor;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.ScoreDoc;

@AllArgsConstructor
@NoArgsConstructor
public class QueryScoreDoc implements Comparable<QueryScoreDoc> {
    public ScoreDoc scoreDoc;
    public Query query;
    public String field;

    public QueryScoreDoc(ScoreDoc scoreDoc, Query query) {
        this.scoreDoc = scoreDoc;
        this.query = query;
    }

    public QueryScoreDoc(ScoreDoc scoreDoc) {
        this.scoreDoc = scoreDoc;
    }

    @Override
    public String toString() {
        return "QueryScoreDoc{" +
                "scoreDoc  " + scoreDoc +
                '}';
    }

    @Override
    public boolean equals(Object obj) {
        QueryScoreDoc o = (QueryScoreDoc) obj;
        if (o.scoreDoc.doc == this.scoreDoc.doc) {
            return true;
        }
        return false;
    }

    @Override
    public int hashCode() {
        return scoreDoc.doc;
    }

    @Override
    public int compareTo(QueryScoreDoc o) {
        return this.scoreDoc.score - o.scoreDoc.score >= 0 ? -1 : 1;
    }
}
